<template>
    <view >
		<view class="head">
			<view class="more">
				<view class="search" v-if="!showInput" @click="showSearchInput">
					<img src="/static/icons/search.png" alt="!" class="searchIcon">
				</view>
				<view v-else class="search-container">
					<input type="text" class="search-input" focus="true" @confirm="searchOpeningGroup" />
					<view @click="hideSearchInput" class="cancel-button">取消</view>
				</view>
			</view>
		</view> 
		
        <view v-for="(item,index) in groupArr" :key="index">
        	<groupCard @goGroupDetail="goGroupDetail(item.id)">
        		<template v-slot:headImg>
        			<image :src="item.avatar" alt="!" class="headImg" mode="aspectFill"></image> 
        		</template>
        		<template v-slot:groupName>
        			{{ item.name }}
        		</template>
        		<template v-slot:groupTag>
        			{{ item.acgnName }}
        		</template>
        	</groupCard>
        </view>
    </view>
</template>

<script>
import {getGroupPage} from '@/api/group.js'
import { data } from 'uview-ui/libs/mixin/mixin'
import groupCard from "../../components/groupCard/groupCard.vue"
export default {
    components: {
        groupCard
    },
	onShow() {
		this.getOpeningGroup()
	},
    data() {
        return {
            keyword: '', // 用户输入的关键词
            tags: [], // 关键词数组
			groupArr:[],
			showInput: false,
        }
    },
	
    methods: {
        showSearchInput() {
            this.showInput = true;
        },
        hideSearchInput() {
            this.showInput = false;
        },
		getOpeningGroup(){
			// const searchText = e.detail.value;
			getGroupPage().then(res=>{
				if(res.data.code==200){
					this.groupArr=res.data.data.records
				}
			})
		},
		searchOpeningGroup(e){
			const data ={
				key: e.detail.value,
			};
			getGroupPage(data).then(res=>{
				if(res.data.code==200){
					this.groupArr=res.data.data.records
				}
			})
		},
		goGroupDetail(id){
			uni.navigateTo({
				url:`/pages/groupDetails/groupDetails?groupId=${id}`
			})
		},
		
    }
}
</script>

<style scoped>
body {
	background-color: #ccc;
}
.head {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 80rpx;
    line-height: 80rpx;
    font-size: 30rpx;
    color: #4D4D4D;
    background-color: #F3F9FC;
}
.more {
    width: 90%;
    position: relative;
    text-align: center;
}

.more .search {
    position: absolute;
    /* width: 30%;
    height: 100%; */
    top: 15rpx;
	right: 0rpx;
    width: 50rpx;
    height: 50rpx;
    
}

.searchIcon {
    /* position: absolute; */
    /* top: 15rpx;
    right: 0; */
    width: 100%;
    height: 100%;
}
.search-container {
    position: absolute;
    right:40rpx;
    width: 85%;
    height: 50rpx;
    line-height: 50rpx;
    border: 1px solid #C0E0EE;
    border-radius: 25rpx;
    margin: 15rpx 0;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    height: 100%;
    text-align: left;
    padding-left: 10rpx;
}
.cancel-button {
    width: 20%;
    height: 100%;
    padding-right: 5rpx;
    color: #84C3DD;
    font-size: 24rpx;
    /* margin-left: 10rpx; */
    /* 在这里设置取消按钮的样式 */
}

/* 团信息 */
.info .headImg {
    position: absolute;
    width: 105rpx;
    height: 105rpx;
    border-radius: 50%;
    left: 40rpx;
    top: 0;
    background-color: #ccc;
}
</style>